package cn.xinfei.xdecision.common.model.datax.consts;

import cn.xinfei.xdecision.common.model.datax.enums.ExecutorEnum;
import cn.xinfei.xdecision.common.model.datax.enums.VariableEnum;
import cn.xinfei.xdecision.common.model.datax.enums.VirtualDataSourceEnum;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class VariableConst {

    public static final String TRACE_ID = "TRACE_ID";

    public static final String HANDLE_NAME = "HANDLE_NAME";

    public static final String COLLECT_STAGE = "COLLECT_STAGE";

    public static final String REQUEST_ID = "requestId";

    public static final String DEFAULT_EMPTY_STR = "";
    public static final String DEFAULT_NULL_STR = "NULL";
    public static final Double DEFAULT_NULL_DUBLE = -99999999D;
    public static final Integer DEFAULT_NULL_INTEGER = -999999;


    public static final String DATA_TRANSFER_FATAL_PREFIX = "dataTransferFatal";
    public static final String VARIABLE_FACTS = "facts";
    public static final String RPC_CONTEXT = "Rpc-Context";

    public static final String BIZ_FLOW_NUMBER = "biz_flow_number";
    public static final String BIZ_TYPE = "biz_type";
    public static final String SEQ_ID = "seq_id";

    public static final String COLUMN_REQUESTER = "requester";
    public static final String COLUMN_INPUT = "input";
    public static final String COLUMN_VARIABLES = "variables";
    public static final String COLUMN_DEFAULT_VARIABLES = "default_variables";


    public static final String ID_CARD_NUMBER = "id_card_number";
    public static final String ID_CARD_PROTYLE = "id_card_protyle";
    public static final String APP = "app";
    public static final String MOBILE = "mobile";
    public static final String INNER_APP = "inner_app";
    public static final String DECISION_RESULT = "result";
    public static final String DECISION_PARAMS = "params";
    public static final String CREDIT_CHANNEL = "credit_channel";
    public static final String ORDER_NUMBER = "order_number";
    public static final String STATUS_PASS = "pass";
    public static final String STATUS_SUCCESS = "success";
    public static final String STATUS_ERROR = "error";
    public static final String STATUS_FAILED = "failed";
    public static final String APPLY_ID = "apply_id";
    public static final String CHANNEL = "channel";
    public static final String TYPE = "type";
    public static final String STAGE = "stage";
    public static final String NAME = "name";


    public static final String SCRIPT_CONTENT = "scriptContent";

    public static final String ZHENG_XIN = "zhengxin";

    public static final String BUSSINESS_PROVIDER = "bussinessEngine";

    public static final String ENUM_PACKAGE = "cn.xinfei.xdecision.common.model.datax.enums.";


    public static final String STATUS_CREDIT_REVIEW = "credit_review";
    public static final String PRODUCT_NAME = "product_name";
    public static final String UPLOAD_CREDIT_SUCCESS = "upload credit success";


    public static final List<String> GROOVY_PRE_VAR_ENUMS = Stream.of(VariableEnum.BASIC_VAR, VariableEnum.CONSTANT_VAR).map(VariableEnum::getCode).collect(Collectors.toList());
    public static final List<String> GROOVY_AFTER_VAR_ENUMS = Stream.of(VariableEnum.DATABASE_VAR, VariableEnum.INTERFACE_VAR, VariableEnum.DERIVE_VAR).map(VariableEnum::getCode).collect(Collectors.toList());


    public static final List<String> BUSSINESS_LABEL_DERIVE_VARS = Arrays.asList(
            "id_card_number_province_label",
            "id_card_number_city_label",
            "mobile_register_time_var",
            "register_utm_source_division",
            "last_activation_result_time_var",
            "last_activation_result_time_copy",
            "last_activation_success_time_var",
            "last_activation_success_time_copy",
            "last_activation_result_var",
            "last_activation_result_copy",
            "last_activation_channel_var",
            "last_activation_channel_copy",
            "initial_credit_line",
            "first_loan_success_time_var",
            "last_order_channel_categories_var",
            "last_order_time_var",
            "last_order_result_var",
            "mobile_utm_source_var"
    );
    public static final List<String> VIRTUAL_EXECUTOR_ENUMS = Stream.of(
            VirtualDataSourceEnum.CREDIT_VAR,
            VirtualDataSourceEnum.JAVA_VAR,
            VirtualDataSourceEnum.PYTHON_VAR,
            VirtualDataSourceEnum.MODEL_VAR).map(VirtualDataSourceEnum::getCode).collect(Collectors.toList());


    public static final List<String> PRE_COLLECT_EXECUTOR_ENUMS = Collections.singletonList(ExecutorEnum.HTTP.name());
    public static final List<String> GROOVY_EXECUTOR_ENUMS = Arrays.asList(ExecutorEnum.GROOVY_PRE.name(), ExecutorEnum.GROOVY_AFTER.name());
    public static final List<Integer> PRE_COLLECT_VAR_TYPE = Arrays.asList(
            Integer.valueOf(VariableEnum.DATABASE_VAR.getCode()),
            Integer.valueOf(VariableEnum.INTERFACE_VAR.getCode())
    );
    public static final List<Integer> REAL_COLLECT_VAR_TYPE = Arrays.asList(
            Integer.valueOf(VariableEnum.BASIC_VAR.getCode()),
            Integer.valueOf(VariableEnum.CONSTANT_VAR.getCode()),
            Integer.valueOf(VariableEnum.DATABASE_VAR.getCode()),
            Integer.valueOf(VariableEnum.DERIVE_VAR.getCode()),
            Integer.valueOf(VariableEnum.INTERFACE_VAR.getCode())
    );
    public static final Map<Integer, String> VAR_AND_EXECUTOR_TYPE_MAP = new HashMap<Integer, String>() {
        {
            put(Integer.valueOf(VariableEnum.DATABASE_VAR.getCode()), ExecutorEnum.SQL.name());
            put(Integer.valueOf(VariableEnum.INTERFACE_VAR.getCode()), ExecutorEnum.HTTP.name());

        }
    };

    public static final Map<String, String> DATASOURCE_AND_EXECUTOR_TYPE_MAP = new HashMap<String, String>() {
        {
            put(VirtualDataSourceEnum.CREDIT_VAR.getCode(), ExecutorEnum.HTTP.getCode());
            put(VirtualDataSourceEnum.JAVA_VAR.getCode(), ExecutorEnum.HTTP.getCode());
            put(VirtualDataSourceEnum.PYTHON_VAR.getCode(), ExecutorEnum.HTTP.getCode());
            put(VirtualDataSourceEnum.MODEL_VAR.getCode(), ExecutorEnum.HTTP.getCode());
            put(VirtualDataSourceEnum.STANDARD_VAR.getCode(), ExecutorEnum.HTTP.getCode());
        }
    };


    public static final Map<String, String> VIRTUAL_DATASOURCE = new HashMap<String, String>() {
        {
            put(VirtualDataSourceEnum.CREDIT_VAR.getCode(), ExecutorEnum.HTTP.getCode());
            put(VirtualDataSourceEnum.JAVA_VAR.getCode(), ExecutorEnum.HTTP.getCode());
            put(VirtualDataSourceEnum.PYTHON_VAR.getCode(), ExecutorEnum.HTTP.getCode());
            put(VirtualDataSourceEnum.MODEL_VAR.getCode(), ExecutorEnum.HTTP.getCode());
        }
    };

    public static final Map<String, String> STANDARD_DATASOURCE = new HashMap<String, String>() {
        {
            put(VirtualDataSourceEnum.STANDARD_VAR.getCode(), ExecutorEnum.HTTP.getCode());
        }
    };


    public static final Integer DERIVE_VAR_TYPE = 4;
    public static final Integer INTERFACE_TYPE = 5;

    public static final Set<String> KEY_WORDS = new HashSet<String>() {{
        add("DELETE ");
        add("DROP ");
        add("TRUNCATE ");
        add("UPDATE ");
        add("ALTER ");
        add("INSERT ");
        add("CREATE ");
        add("RENAME ");
    }};
}
